<template>
  <div class="container">
    <input type="text" v-model="user.username"><br>
    <input type="password" v-model="user.password"><br>
    <button @click="toLogin(user)">登录</button>
  </div>
</template>

<script>
import { login } from '@/api/user.js'
import { setToken } from '@/utils/auth'
export default {
  name: '',
  components: {},
  props: {},
  data () {
    return {
      user: {
        username: 'admin',
        password: '123456'
      }
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    async toLogin (user) {
      const { data: token } = await login(user)
      // console.log('token:', token.token)
      setToken(token.token)
      this.$store.commit('SET_TOKEN', token.token)

      this.$router.push({
        path: '/'
      })
    }
  }
}
</script>

<style scoped lang="">

</style>
